package com.xjnt.base.support.admin.common.beetl.fn;

import java.util.List;

import org.beetl.core.Context;
import org.beetl.core.Function;

import com.xjnt.base.support.admin.service.DictionaryService;
import com.xjnt.base.support.admin.service.MenuService;
import com.xjnt.base.support.admin.service.PlatformService;

public class ModelSelFunction implements Function {

	private static final DictionaryService dictService = new DictionaryService();
	private static final PlatformService platfromService = new PlatformService();
	private static final MenuService menuService = new MenuService();
	
	@Override
	public Object call(Object[] paras, Context ctx) {
		Object o = paras[0];
		Object v = paras[1];
		if(o != null && v != null){
			return modelSelect(o.toString(), v.toString());
		}
		return null;
	}
	
	private List<?> modelSelect(String modelName, String type){
		if(modelName.equals("dictionary")){
			return dictService.findByType(Integer.parseInt(type));
		} else if (modelName.equals("platform")){
			return platfromService.findAll();
		} else if (modelName.equals("menu")){
			return menuService.findByType(Integer.parseInt(type));
		}
		return null;
	}

}
